local _M = {
    version = 0.1,
    priority = 0,
    name = "consul_plugin",

}
local ConsulUtil = require("demo.consul.ConsulUtil")
local  config_local = require("core.config_local")
function _M:init_worker(conf)

    print("执行了consul_plugin")
    ngx.log(ngx.INFO,"执行了consul_plugin");
    ---服务注册
    --ConsulUtil.registerServer("192.168.212.74",8500,"apiservice9","apiservice9","172.200.96.106",8089,"http://172.200.96.106:80/health");
    --ngx.log(ngx.INFO,"获取配置信息");
    -----配置获取 并监听变更
    --print("获取配置信息")
    --
    --local properties = ConsulUtil.get_Config_from_consul("192.168.212.74",8500,
    --        "gcd/gcd-bridge-provider/gcd-bridge-provider-dev.properties",
    --        "data-center-1")
    --
    --
    --
    --
    --for i,v in pairs(properties) do
    --    ngx.log(ngx.INFO,"key:" ..i.." value: ".. v);
    --    print("key:" ..i.." value: ".. v)
    --
    --
    --end
    --
    --
    --local config_data = config_local.local_conf()
    --
    --config_local.merge_conf(config_data,properties);
    --
    --print("plugins init_worker==============> consul_plugin")
    --
    --print("consul init_worker ")
    --
    --
    --
    local watch = require "demo.consul.ConsulWatch";
    --ngx.log(ngx.INFO,"初始化consul watch")
    --local broker_watch = watch:new(
    --        "http://192.168.212.74:8500/v1/kv/config/gcd/gcd-bridge-provider/gcd-bridge-provider-dev.properties",
    --        function(co, k)
    --            ngx.log(ngx.INFO,"日志发生变化了")
    --            ngx.log(ngx.INFO, "callback key:", k[1]["Key"])
    --
    --
    --            local properties = ConsulUtil.get_Config_from_consul("192.168.212.74",8500,
    --                    "gcd/gcd-bridge-provider/gcd-bridge-provider-dev.properties",
    --                    "data-center-1")
    --            local _config_data = config_local.local_conf()
    --
    --
    --            config_local.merge_conf(_config_data,properties);
    --
    --
    --            if  _config_data["c"] ~= nil then
    --                print("修改后的config_data".._config_data["c"]);
    --            end
    --
    --
    --
    --            --如果有变化了 ,就重新开始加载配置文件
    --        end
    --)
    --ngx.log(ngx.INFO,"开始watch consul 的变化")
    --broker_watch:start()

    -----------获取配置信息



    local service_watch = watch:new(
            "http://192.168.212.74:8500/v1/health/service/open-platform-admin-mining-provider",
            function(co, k)
                ngx.log(ngx.INFO,"》》》》》》》》 consul服务发生了变化")



                --如果有变化了 ,就重新开始加载配置文件
            end
    )
    ngx.log(ngx.INFO,"开始watch consul service open-platform-admin-mining- 变化")
    service_watch:start()



    --local serviceNode = ConsulUtil.getServiceNodes("192.168.212.74",8500,"smarthome-es-srv");
    --
    --for i,v in pairs(serviceNode) do
    --    print("获取到的服务节点为"..v.ip .."端口为"..v.port);
    --end

end




return _M